package cn.javasea.rbac.shiro.util;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 登录信息
 * @author xiangchao
 * @date 2023/2/2 15:11
 */
public class LoginInfor implements Serializable {

    private static final long serialVersionUID = -771733113771658588L;

    private String userName;  //用户名
    private String password;  //密码
    private String verifyCode; //验证码
    private Boolean useMobile = false; //是否使用手机验证，默认false
    private String mobile;//手机号
    private String mobileCode;//手机验证码
    private String token;
    private String ip;
    public String valid() {
        if(StringUtils.isEmpty(userName)) {
            return "用户名不能为空";
        }
        if(StringUtils.isEmpty(password)) {
            return "密码不能为空";
        }
        if(StringUtils.isEmpty(verifyCode)) {
            return "验证码不能为空";
        }
//        String captcha = ShiroAuthenticationManager.getKaptcha(GlobalConstan.KAPTCHA_SESSION_KEY);
//        if(StringUtils.isEmpty(captcha) || !verifyCode.equalsIgnoreCase(captcha)) {
//            throw new MsgException("验证码不正确");
//        }
        if(useMobile.booleanValue()){
            if(StringUtils.isEmpty(mobileCode)) {
                return "手机验证码不能为空";
            }
        }
        return null;
    }

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getVerifyCode() {
        return verifyCode;
    }
    public void setVerifyCode(String verifyCode) {
        this.verifyCode = verifyCode;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getMobileCode() {
        return mobileCode;
    }

    public void setMobileCode(String mobileCode) {
        this.mobileCode = mobileCode;
    }

    public Boolean getUseMobile() {
        return useMobile;
    }

    public void setUseMobile(Boolean useMobile) {
        this.useMobile = useMobile;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}
